package servlet;

import entity.Health;
import service.HealthService;
import service.impl.HealthServiceImpl;
import util.ScannerUtils;

import java.util.ArrayList;

public class UserHealth {
    HealthService healthService = new HealthServiceImpl();
    public void userList(String idNumber) throws Exception{
        System.out.println("健康信息");
        System.out.println("请选择：");
        System.out.println("1.查看健康记录");
        System.out.println("2.添加健康记录");
        String choice = ScannerUtils.scannerUtil();
        if (choice.equals("1")){
            listHealth(idNumber);
        } else if (choice.equals("2")) {
            addHealth(idNumber,null);
        }
    }
    public void listHealth(String idNumber) throws Exception{
        ArrayList<Health> list = healthService.findHealth(idNumber);
        for (int i = 0; i < list.size(); i++){
            System.out.println(list.get(i).getHealth());
        }
        UserLife userLife = new UserLife();
        userLife.userList(idNumber);
    }
    public void addHealth(String idNumber, String health) throws Exception{
        if (health == null){
            System.out.println("请输入新的健康记录");
            health = ScannerUtils.scannerUtil();
            healthService.insert(idNumber,health);
            UserLife userLife = new UserLife();
            userLife.userList(idNumber);
        }else {
            healthService.insert(idNumber,health);
        }
    }
}
